package com.lagou.dao;

import com.lagou.entity.Phone;
import com.lagou.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class PhoneDao {
    /**
     * 查询价格高于2000元，生产日期是2019年之前的所有手机
     */

    public List<Phone> getPhoneByPriceAndYear(double price, String year) throws SQLException {
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
        String sql = "select * from phone where price > ? and year(prodate) < ?";
        Object[] params = {price,year};

        return qr.query(sql,new BeanListHandler<Phone>(Phone.class),params);
    }
    public List<Phone> getPhoneByColor(String color) throws SQLException {

        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
        String sql = "select * from phone where color = ?";
        List<Phone> query = qr.query(sql, new BeanListHandler<Phone>(Phone.class), color);
        return query;
    }


}
